package ch03.d6;
//java bean 完全封装类
//1.属性私有化
//2.提供getter setter方法
//3.提供无参构造器

import java.util.Objects;

public class Student {
    private String name;
     int age;

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        if(age<0||age>100){
            throw new RuntimeException("年龄不合法");
        }
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public boolean equals(Student t){
        // 两个对象：this和t
        //谁调用这个方法，this就是谁
        return this.name==t.name && this.age==t.age;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return age == student.age && Objects.equals(name, student.name);
    }

}
